home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / StreamImageSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  1.9 KB  |  62 lines

  1. package symantec.itools.awt.image;
  2.  
  3. import java.awt.image.ImageProducer;
  4. import java.io.BufferedInputStream;
  5. import java.io.InputStream;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8. import sun.awt.image.GifImageDecoder;
  9. import sun.awt.image.ImageDecoder;
  10. import sun.awt.image.JPEGImageDecoder;
  11. import sun.awt.image.URLImageSource;
  12.  
  13. public class StreamImageSource extends URLImageSource implements ImageProducer {
  14.    InputStream stream;
  15.    int type;
  16.    URL base;
  17.    static URL baseUrl;
  18.    public static final int GIF = 0;
  19.    public static final int JPEG = 1;
  20.  
  21.    public StreamImageSource(InputStream is, int type) {
  22.       this(baseUrl, is, type);
  23.    }
  24.  
  25.    public StreamImageSource(URL base, InputStream is, int type) {
  26.       super(base);
  27.       if ((type & 1) == 0) {
  28.          throw new IllegalArgumentException("Unsupported image type:" + type);
  29.       } else {
  30.          this.stream = is;
  31.          this.type = type;
  32.       }
  33.    }
  34.  
  35.    public static void setBaseUrl(URL base) {
  36.       baseUrl = base;
  37.    }
  38.  
  39.    public static URL getBaseUrl() {
  40.       return baseUrl;
  41.    }
  42.  
  43.    protected ImageDecoder getDecoder() {
  44.       InputStream is = new BufferedInputStream(this.stream);
  45.       switch (this.type) {
  46.          case 0:
  47.             return new GifImageDecoder(this, is);
  48.          case 1:
  49.             return new JPEGImageDecoder(this, is);
  50.          default:
  51.             throw new IllegalArgumentException("Unsupported image type:" + this.type);
  52.       }
  53.    }
  54.  
  55.    static {
  56.       try {
  57.          baseUrl = new URL("file://");
  58.       } catch (MalformedURLException var0) {
  59.       }
  60.    }
  61. }
  62.